<?php
namespace Admin\Controller;
use Think\Controller;

class BaseController extends Controller
{
    protected function _initialize()
    {
        $this->checkAdmin();
    }
    
	/**
	 * 判断用户是否已经登陆
	 */
	protected function checkAdmin()
    {
		//用于swfupload上传文件丢失cookie，通过手工传cookie名处理
		if (isset($_POST['PHPSESSID'])) {
			session_id($_POST["PHPSESSID"]);
		}
		if ('login' == ACTION_NAME || 'verify' == ACTION_NAME) {
			return true;	
		} else if (!session('?admin_id') || !session('?admin_name')) {
			$this->error('登录超时或未登录！', U('Public/login'));
		} else {
			return true;	
		}
	}
	
	/**
	 * 权限判断
	 */
	protected function checkPriv()
    {
		return true;	
	}
    
	/**
	 * 获取旅游地区列表
	 */
	public function ajaxGetAreaListAction()
    {
		$return = array('error_num' => 0, 'error_msg' => '', 'content' => '');
		$pid = I('parent_id', 0, 'intval');
		
		$Area = D('Area');
		$area_list = (array)$Area->where('pid=' . $pid)->select();
		$select = '';
		foreach($area_list as $item_area) {
			$select .= "<option value='" . $item_area['id'] . "'>" . $item_area['name'] . "</option>";
		}
		$return['content'] = $select;
		$this->ajaxReturn($return);	
	}
    
	/**
	 * 获取地区列表
	 */
	public function ajaxGetRegionListAction() {
		$arr_return = array('error_num' => 0, 'error_msg' => '', 'content' => '');
		$parent_id = I('parent_id', 0);
        
		$Region = M('Region');
		$region_list = (array)$Region->where('parent_id=' . $parent_id)->select();
		$select = '';
		foreach($region_list as $item) {
			$select .= "<option value='" . $item['id'] . "'>" . $item['region_name'] . "</option>";
		}
		$arr_return['content'] = $select;
		$this->ajaxReturn($arr_return);	
	}
}